package com.yueka.controller;

import com.yueka.pojo.R;
import com.yueka.pojo.entity.student.Student;
import com.yueka.pojo.entity.student.StudentQueryParam;
import com.yueka.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/student")
@RestController
public class StudentController {

    @Autowired
    StudentService studentService;

    @GetMapping("/list")
    public R getStudentList(StudentQueryParam studentQueryParam) {
        try {
            System.out.println(studentQueryParam);
            return R.success(studentService.getStudentList(studentQueryParam));
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }

    @GetMapping("/getInIds")
    public R getInIds(Integer[] ids) {
        try {
            return R.success(studentService.getInIds(ids));
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }

    @PostMapping("/insert")
    public R insertStudent(@RequestBody Student student) {
        try {
            studentService.insertStudent(student);
            return R.success();
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }

    @PostMapping("/update")
    public R updateStudent(@RequestBody Student student) {
        try {
            studentService.updateStudent(student);
            return R.success();
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }

    @PostMapping("/login")
    public R login(@RequestBody Student student) {
        try {
            return R.success(studentService.login(student));
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }
}
